function getMeshIdx( name, meshArray)
{
  for(var i=0;i< meshArray.length;i++)
  {
    if( name == meshArray[i].name)
      return i;
  }
  return -1;
}
function getMaterialFromName(name)
{
  var eList = this.game.getScreen(DESIGN_SCREEN_ID).scene3d.effects;
  var eLen = eList.length;
  for(var i=0;i<eLen;i++)
  {
    var mList = eList[i].materialList; 
    for(var m in mList  )
    {
      if(m==name)
        return mList[m];
    }
  } 
  return null;
}
function getMeshName(mesh)
{
  var meshList = this.game.resourceManager.meshManager.meshList;
  for(var i in meshList)
  {
    if( meshList[i]==mesh)
      return i;
  }
  return "";
}
function getFloatMapName(map)
{
  var mapList = this.game.resourceManager.floatMaps;
  for(var i in mapList)
  {
    if( mapList[i]==map)
      return i;
  }
  return "";
}

function getTexName(tex)
{
  var texList = this.game.resourceManager.textureManager.textureList;
  for(var i in texList)
  {
    if( texList[i]==tex)
      return i;
  }
  return "";
}
/////////////////////////////////////
// Color picker utils
function myRGBToHex(rgb) 
{
  var hex = [
    rgb.r.toString(16),
    rgb.g.toString(16),
    rgb.b.toString(16)
  ];
  $.each(hex, function (nr, val) {
    if (val.length == 1) {
      hex[nr] = '0' + val;
    }
  });
  return hex.join('');
}
function setColorPicker(id,r,g,b)
{
  var color = {};
  color.r = Math.floor(r*255.);
  color.g = Math.floor(g*255.);
  color.b = Math.floor(b*255.); 
  eval("$('#"+id+"').ColorPickerSetColor(color);");
  eval("$('#"+id+"').outColor=color;");
  var hex = myRGBToHex(color);
  eval("$('#"+id+" div').css('backgroundColor', '#"+hex+"');");
  window.colorPicker[id] =  color;
}
function createColorPicker(id,callback)
{
  eval("$('#"+id+"').ColorPicker({\
    color: '#0000ff',\
    onShow: function (colpkr) {\
      $(colpkr).fadeIn(500);\
      return false;\
    },\
    onHide: function (colpkr) {\
      $(colpkr).fadeOut(500);\
      return false;\
    },\
    onChange: function (hsb, hex, rgb) {\
      $('#"+id+" div').css('backgroundColor', '#' + hex);\
      window.colorPicker[id] =  rgb;\
      this.outColor = rgb;\
      "+callback+"();\
    }\
  })")
}
//////////////////////////////////////////////////////
// UI Tab utils
function setActiveInfoTab(id)
{
  $("#info_tabs").tabs("option","selected",id); 
}
function addInfoTab(url,label)
{
  $("#info_tabs").tabs("add",url,label); 
   var len = $("#info_tabs").tabs("length");
  $("#info_tabs").tabs("select",len-1);
}
function clearInfoTab()
{
  $("#info_tabs").tabs( "abort" );
  var len = $("#info_tabs").tabs("length");
  for(var i=len-1;i>0;i--)
  {
    $("#info_tabs").tabs("remove",i);
  }
}
///////////////////////////////////////////////////////////////////////
// List Utils
function getTextFromList(list_id)
{
  var list = document.getElementById(list_id);
  if(list.selectedIndex==-1)
    return "";
  else
    return list.options[list.selectedIndex].text;
}
function addOptionToList(opText,list_id)
{
  var list = document.getElementById(list_id);
  var op=document.createElement('option');
  op.text = opText;
  list.add(op,null);
} 
function getTextFromInput(id)
{
  var input = document.getElementById(id);
  return input.value;
}
function isNumberKey(evt)
{
   var charCode = (evt.which) ? evt.which : event.keyCode
   if(charCode==46) // '.'
    return true; 
   if(charCode==45) // '-'
    return true;
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

   return true;
}

function getClassName(obj) 
{
  // get classname abstracted from
  // constructor property
  var c = obj.constructor.toString();
  var start = c.indexOf('function ') + 9;
  var stop = c.indexOf('(');
  c = c.substring(start, stop);
  return c;
}
